home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / sbprocss / sbsample.c < prev    next >
Text File  |  1995-01-14  |  1KB  |  80 lines

  1. /* sbsample.c */
  2.  
  3. #define TRUE  1
  4. #define FALSE 0
  5.  
  6. unsigned int resetport = 0x226;
  7. unsigned int readport  = 0x22A;
  8. unsigned int writeport = 0x22C;
  9. unsigned int pollport  = 0x22E;
  10.  
  11. void out(unsigned int port, unsigned char value)
  12.   {
  13.     asm {
  14.       mov    dx, port
  15.       mov    al, value
  16.       out    dx, al
  17.      }
  18.   }
  19.  
  20. void writedsp(unsigned char value)
  21.   {
  22.      wait:
  23.       asm {
  24.       mov    dx, writeport
  25.       in     al, dx
  26.       and    al, 0x80
  27.       jnz    wait
  28.       mov    al, [value]
  29.       out    dx, al
  30.      }
  31.   }
  32.  
  33. unsigned char readdsp(void)
  34.   {
  35.      wait:
  36.     asm {
  37.       mov    dx, pollport
  38.       in     al, dx
  39.       and    al, 0x80
  40.       jz     wait
  41.       mov    dx, readport
  42.       in     al, dx
  43.      }
  44.   }
  45.  
  46. char resetdsp(void)
  47.   {
  48.     char i;
  49.  
  50.     out(resetport, 1);
  51.     out(resetport, 0);
  52.     i = 100;
  53.     while (!i && (readdsp() != 0xAA)) i++;
  54.     if (!i)
  55.       return FALSE;
  56.       else return TRUE;
  57.   }
  58.  
  59. void turnspeakeron()
  60.   {
  61.     writedsp(0xD1);
  62.   }
  63.  
  64. void turnspeakeroff()
  65.   {
  66.     writedsp(0xD3);
  67.   }
  68.  
  69. unsigned char getsample(void)
  70.   {
  71.     writedsp(0x20);
  72.     return readdsp();
  73.   }
  74.  
  75. void outputsample(unsigned char sample)
  76.   {
  77.     writedsp(0x10);
  78.     writedsp(sample);
  79.   }
  80.